package way.server;

import java.util.ArrayList;
import java.util.List;

import way.server.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.Toast;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.ItemizedOverlay;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.mapapi.map.PopupClickListener;
import com.baidu.mapapi.map.PopupOverlay;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.baidu.platform.comapi.map.Projection;


      
// 同一类型覆盖物的绘制  
class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {  
    // 属性  
    private Context mContext;  
    private List<OverlayItem> geoList = new ArrayList<OverlayItem>();  
    private double dLat;  
    private double dLon;  
    static PopupOverlay pop = null;
    
    // 构造方法  
    public MyItemizedOverlay(Drawable marker, Context context) {  
        super(marker);  
   
        this.mContext = context;  
        //深圳 ，114.06667,22.61667
        dLat = 114.06667;
        dLon = 22.61667;
        // 构造地理坐标  
        GeoPoint p1 = new GeoPoint((int) (dLat * 1E6), (int) (dLon * 1E6));  
        geoList.add(new OverlayItem(p1, "P1", "这是我的当前位置"));  
        pop = new PopupOverlay( LocationAllShow.mMapView,new PopupClickListener() {
			
			@Override
			public void onClickedPopup() {
				 Log.d("hjtest  ", "clickpop");
			}
		});
	  
        populate();// 执行填充方法  

    }  


    // 添加成员方法  
    @Override  
    protected OverlayItem createItem(int i) {  

        return geoList.get(i);  
    }  

    @Override  
    public int size() {  

        return geoList.size();  
    }  
	public void addItem(OverlayItem item){
		geoList.add(item);
		populate();
	}
	public void removeItem(int index){
		geoList.remove(index);
		populate();
	}

    // 添加点击事件  
    public boolean onTap(int index) {  
          
        Drawable marker = this.mContext.getResources().getDrawable(R.drawable.pop);  //得到需要标在地图上的资源
		BitmapDrawable bd = (BitmapDrawable) marker;
        Bitmap popbitmap = bd.getBitmap();
	    pop.showPopup(popbitmap, geoList.get(index).getPoint(), 32);
		// int latspan = this.getLatSpanE6();
		// int lonspan = this.getLonSpanE6();
		Toast.makeText(this.mContext, geoList.get(index).getTitle(), Toast.LENGTH_SHORT).show();
		super.onTap(index);
		return false;
    }  

    public boolean onTap(GeoPoint point, MapView mapView) {  
        return super.onTap(point, mapView);  
    }  
 }
  
